package com.linghang.demo.controller;


import com.linghang.demo.domain.User;
import com.linghang.demo.req.UserQueryReq;
import com.linghang.demo.resp.CommonResp;
import com.linghang.demo.resp.PageResp;
import com.linghang.demo.resp.UserQueryResp;
import com.linghang.demo.service.UserService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

//用户
@RestController
@RequestMapping ("/user")
public class UserController {


    @Resource
    private UserService userService;


    @GetMapping("/list1")
    public CommonResp list() {
        CommonResp<List<User>> resp = new CommonResp<>();
        List<User> list = userService.list();
        resp.setContent(list);
        return resp;
    }
    @GetMapping("/list")
    public CommonResp list(@Valid UserQueryReq req) {
        CommonResp<PageResp<UserQueryResp>> resp = new CommonResp<>();
        PageResp<UserQueryResp> list = userService.list(req);
        resp.setContent(list);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable int id){
        CommonResp resp=new CommonResp<>();
        userService.delete(id);

        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody UserQueryReq req) {
        CommonResp resp = new CommonResp<>();
        userService.save(req);
        return resp;
    }
}